﻿function addHtml(width) {
    if (width) {
        var trs = '<div id="showConsultant">';
        trs += ' <div class="font_show" id="show_1"  style="margin-left:20px;margin-right:0px;width:' + width + 'px;"></div>';  //840px
        trs += " </div> ";
        return trs;
    }
    else {
        var trs = '<div id="showConsultant">';
        trs += ' <div class="font_show" id="show_1"  style="margin-left:20px;margin-right:0px;width:540px;"></div>';  //840px
        trs += " </div> ";
        return trs;
    }

}

//显示问题
function addHtml2(width) {
    if (width) {
        var trs = '<div id="showConsultant">';
        trs += ' <div class="font_show" id="show_1"  style="margin-left:10px;margin-right:0px;float:left;width:260px;border-right:5px solid rgba(0, 0, 0, 0.2);position:relative;overflow-y:auto;height:599px;"></div>';  //840px
        trs += '<div class="font_show" id="show_2" style="margin-left:290px;position:relative;overflow-y:auto;height:599px;width:430px;"></div>';
        trs += " </div> ";
        return trs;
    }
    else {
        var trs = '<div id="showConsultant">';
        trs += ' <div class="font_show" id="show_1"  style="margin-left:10px;margin-right:0px;float:left;width:260px;border-right:5px solid rgba(0, 0, 0, 0.2);position:relative;overflow-y:auto;height:599px;"></div>';  //840px
        trs += '<div class="font_show" id="show_2" style="margin-left:290px;position:relative;overflow-y:auto;height:599px;width:430px;"></div>';
        trs += " </div> ";
        return trs;
    }
}

//显示置业顾问
function showConsultant(data) {
    $("#show_1").html("");
    var d = eval(data);
  
    for (var i = 0; i < d.length; i++) {
        $("#show_1").append(
            "<div id=" + d[i].id + " class='button button-small button-rounded' style='margin-bottom: 8px; padding:0px; margin-right: 5px;width: 100px; float:left' onclick='changeConsultant2(this)'>"
            + d[i].text + "</div>");
    }
   
}

//更改置业顾问
function changeConsultant2(obj) {
    var d = $(obj).html();
    var i = obj.id;

    if (d == "全部") {
        x.find("span").html("置业顾问");
    }
    else {
        x.find("span").html(d);
    }
    $("#consultant_Id").val(i);
    document.getElementById('fade').style.display = 'none';
    $("#consultantbutton").removeClass("white_content2");
    $("#consultantbutton").addClass("black_content2");
    doserch();
}

//以下是来访登记页面的置业顾问显示
function showConsultant2(data) {
    $("#show_1").html("");
    $("#show_2").html("");
    var d = eval(data);
   
    for (var i = 0; i < d.length; i++) {
        $("#show_1").append(
            "<div id=" + d[i].id + " class='layui-btn' style='margin-bottom: 8px; padding:0px; margin-right: 5px;width: 100px; float:left' onclick='changeConsultant3(this)'>"
            + d[i].text + "</div>");
    }
}

//客户来访节点
function changeConsultant3(obj) {
    var d = $(obj).html();
    var i = obj.id;

    $("#consultantN").html(d);
    $("#consultant_Id").val(i);
    $("#consultant_Name").val(d);
    document.getElementById('fade').style.display = 'none';
    $("#consultantbutton").removeClass("white_content2");
    $("#consultantbutton").addClass("black_content2");
}

//显示问题选择
function showConsultant3(data) {
    $("#show_1").html("");
    $("#show_2").html("");
    var d = eval(data);
    var t = getCookie("tt" + key);
    var lhTt = JSON.parse(t);

    if (lhTt == null) {
        $("#show_1").append(
            "<div  style='margin-bottom: 8px; padding:0px; margin-right: 5px;width: auto; float:center;color: white;font-size: large;'>"
            +"暂无记录</div>");
    } else {
        for (var j = 0; j < lhTt.length; j++) {
            $("#show_1").append(
                "<div id=" + lhTt[j].id + "  class='button button-small button-rounded' style='margin-bottom: 8px; padding:0px; margin-right: 5px;width: auto; float:left' onclick='changeConsultant4(this)'>"
                + lhTt[j].name + "</div>");
        }
    }
    
    for (var i = 0; i < d.length; i++) {
        $("#show_2").append(
            "<div id=" + d[i].id + " class='button button-small button-rounded' style='margin-bottom: 8px; padding:0px; margin-right: 5px;width: auto; float:left' onclick='changeConsultant4(this)'>"
            + "<span>" + (i+1) + ".</span>" + d[i].text + "</div>");
    }

}

//更改问题选择
var array1 = [];
var array2 = [];
var arr2;

function getHistory() {
    var qjT = getCookie("tt" + key);
    var qjTt = JSON.parse(qjT);
    if (qjTt == null || qjTt.length == 0) {
        array1 = [];
    }
    else {
        array1 = qjTt;
    }
}

var checkCol = function (data, col) {
    for (var i in data) {
        if (data[i].id == col) {
            return true;
        }
    }
    return false;
};

function changeConsultant4(obj) {
    getHistory();
    var d = $(obj).html();
    var qId = obj.id;

    //if (d == "全部") {
    //    x.find("span").html("置业顾问");
    //}
    //else {
    //    x.find("span").html(d);
    //}
    $("#consultantN").html(d);
    $("#consultant_Id").val(i);
    $("#consultant_Name").val(d);

    SetCookie("i", i,30);

    var arr = { "id": qId, "name": d };
    array1.push(arr);
    for (var i = 0; i < array1.length; i++) {
        if (!checkCol(array2, array1[i].id)) {                                                            
            //不重复的时候，新增
            array2.push({ id: array1[i].id, name: array1[i].name });
        }
    }
    SetCookie("tt" + key, JSON.stringify(array2), 30);

    $("#consultant_Id").val(qId) || $("#consultant_Id").val(getCookie("i"));
    document.getElementById('fade').style.display = 'none';
    $("#consultantbutton").removeClass("white_content2");
    $("#consultantbutton").addClass("black_content2");
    doserch();
}


//关闭弹出层
function CloseDiv() {
    document.getElementById('fade').style.display = 'none';
    $("#starsetbutton").removeClass("white_content");
    $("#starsetbutton").addClass("black_content");
    $("#consultantbutton").removeClass("white_content2");
    $("#consultantbutton").addClass("black_content2");
}